<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%
	request.setAttribute("path", request.getContextPath());
%>
<script type="text/javascript">
$(function(){
});
function selectAll(obj){
	$("#stockDataList input[name='chkStock']").prop("checked",$(obj).prop("checked"));
}
function removeProductPart(){

	$("#stockDataList input[name='chkStock']:checked").each(function(){
		$(this).parents("tr").remove();

	});
}
function check(){

	var fromShop = $("#fromShopId").val();
	var toShop = $("#toShopId").val();

	if(common.isEmpty(fromShop) || common.isEmpty(toShop)){
		common.modalGlobalMessage("请设置仓库和网点信息!");
		return false;
	}
	
	var size = $("input[name='requestItemNum']").size();
	if(size < 1){
		common.modalGlobalMessage("请输入库存信息!");
		return false;
	}

	
	var result = true
	$("input[name='requestItemNum']").each(function(){
		var num = $(this).val();
		if(common.isEmpty(num) || common.isNotInteger(num)){
			common.modalGlobalMessage("请输入大于0的库存数量!");
			result = false;
			return false;
		}
	});
	return result;
}
function save(){

	if(check()){
		var uri = "${root}/stock/request/submit"
		common.ajaxSubmit(uri,"stockForm","提交库存失败","",'common.reload("${root}/stock/list/init?h=h03&n=n01")');
	}
}
function searchProductPart(){

	var partId = $("#productPartId").val();
	var partName = $("#productPartName").val();
	if(common.isEmpty(partId) && common.isEmpty(partName)){
		
		common.modalGlobalMessage("请输入配件编码或者配件名称!");
		return false;
	}
	var param ={};
	param.stockType= $("#stockType").val();
	param.toShopId= $("#toShopId").val();
	param.productPartId = partId;
	param.productPartName = partName;
	param.requestType = "in";
	
	var uri = "${root}/stock/search/item";
	$.post(uri,param,function(html){
		$("#stockDataList").append(html);
	});
}
function popShops(){

	var uri = "${root}/shop/list/pop/init/warehouse";
	$.post(uri,function( html ){
		common.moalYesNoDialog(html,"仓库选择","selectShop()");
	});
}
function selectShop(){

	var $checkedItem = $("input[name='rdShopItem'][type='radio']:checked");
	$("#fromShopId").val($checkedItem.val());
	$("#fromShopName").text($checkedItem.attr("title"));
	common.closeYesNoDialog();
	
}
</script>
<form class="form-horizontal" id="stockForm" role="form">
<input name="requestType" type="hidden" value="in">
<fieldset class="fieldset" >
	<legend>入库基本信息</legend>
	<table class="table table-hover">
		<tr>
			<th>手动编号:</th>
			<td><input type="text" class="input-xlarge" name="manualId" id="manualId" maxlength="50"/></td>
			<th>发货仓库:</th>
			<td>
				<button  class="btn btn-success btn-samll" type="button" onclick="popShops()">选择</button>
				<input type="hidden" name="fromShopId" id="fromShopId"/>
				<span class="input-xlarge uneditable-input" id="fromShopName"></span>
			</td>
		</tr>
		<tr>
			<th>配件库存类型:</th>
			<td>
				<select name="stockType" id="stockType" class="input-xlarge" >
					<c:forEach var="item" items="${stockProductTypes}">
						<option value="${item}"><spring:message code="${item}"/></option>
					</c:forEach>
				</select>
			</td>
			<th>网点名称:</th>
			<td>
		    	<select id="toShopId" name="toShopId" class="input-xlarge" >
					<c:forEach var="item" items="${shops}">
						<option value="${item.id }"><c:out value="${item.name }"/></option>
					</c:forEach>
				</select>
			</td>
		</tr>
		<tr>
			<th>申请人:</th>
			<td>
				<input type="text" class="input-xlarge" name="requestUser" id="requestUser" value="${userMe.name}"/>
			</td>
			<th>申请日期:</th>
			<td >
		    	<input type="text" data-date="${today}"  data-date-format="yyyy-mm-dd" class="input-medium datepicker" id="requestDate" name="requestDate" >
			</td>
		</tr>
		<tr>
			<th>备注:</th>
			<td colspan="3"><input type="text" class="input-xxlarge" name="requestCommont" id="requestCommont" maxlength="500"/></td>
		</tr>
	</table>
</fieldset>

<fieldset class="fieldset" >
	<legend>入库库存信息</legend>
	<table class="table table-hover">
		<tr>
			<th>配件编码:</th>
			<td><input type="text" class="input-xlarge" name="productPartId" id="productPartId"/></td>
			<th>配件名称:</th>
			<td><input type="text" class="input-xlarge" name="productPartName" id="productPartName"/></td>
			<td>
				<button type="button" class="btn btn-success btn-small" onclick="searchProductPart()">增加</button>
		      	<button type="button" class="btn btn-warning btn-small" onclick="removeProductPart()">删除</button>
			</td>
		</tr>
	</table>

<table class="table table-striped table-bordered">
	<thead>
		<tr >
		    <th class="span1 text-center">
				<input type="checkbox" onclick="selectAll(this)">
		    </th>
			<th class="span3 text-center">配件编码</th>
			<th class="text-center">配件名称</th>
			<th class="span2 text-center">价格</th>
			<th class="span2 text-center">库存</th>
			<th class="span2 text-center">申请数量</th>
			<th class="span4 text-center">备注</th>
		</tr>
	<tr>
	</thead>
	<tbody id="stockDataList">
	</tbody>
</table>
</fieldset>
<div class="form-actions text-center">
	  <button type="button" class="btn btn-success" onclick="save()">保存</button>
 </div>
</form>

